// pages/content/updatepwd.js
var rsa = require('../../utils/rsa.js')
var mdk = require('../../utils/md55.js');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orpwd: '',
    newpwd: '',
    mkpwd: '',
    tel:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
      wx.getStorage({
        key: 'phoneNum',
        success: function(res) {
          that.setData({
            tel:res.data,
          })
        },
      })
  },
  //确定
  makesure:function(){
    const p1 = this.data.orpwd;
    const p2 = this.data.newpwd;
    const p3 = this.data.mkpwd;
    if(p1 == '' || p2=='' || p3 == ''){
      wx.showToast({
        title: '密码不为空',
        icon: 'none',
        duration: 3000
      })
      return;
    }
    if(p2!=p3){
      wx.showToast({
        title: '新密码设置不一致',
        icon: 'none',
        duration: 3000
      })
      return;
    }
    var shopnum = app.globalData.shoopnum;
    const setion = app.globalData.session;
    var opwd = mdk.hexMD5(p1);
    var npwd = mdk.hexMD5(p3);
    wx.showLoading({
      title: '加载中',
    })
    var tel = this.data.tel;
    rsa.Cpic_fetchPost(rsa.SERVERPORT, {
      'method': 'promotion.updatepsw', "seller_bn": shopnum, "session_id": setion, "old_psw": opwd, "new_psw": npwd, 'mobile': tel }, (err, res) => {
        wx.hideLoading()
        var rescode = res.return_code;
        var msg = res.return_msg;
        if(rescode =='0000'){
        
          wx.showModal({
            title: '修改成功',
            content: '返回登录界面',
            showCancel:false,
            success: function (res) {
              if (res.confirm) {
                wx.reLaunch({
                  url: '/pages/index/index'
                })
              }
            } 
          })
        }else{
          wx.showModal({
            title: '提示',
            content: err,
            showCancel: false,
            success: function (res) {
             
            }
            })
        }
    })

    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  orgpwd: function (e) {

    this.setData({
      orpwd: e.detail.value,
    })
  },
  newpwd: function (e) {
    this.setData({
      newpwd: e.detail.value,
    })
  },
  calpwd: function (e) {
    this.setData({
      mkpwd: e.detail.value,
    })
  }
})